﻿namespace Ex04.Menus.Test
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Ex04.Menus.Delegates;

    public class DelegateMenu
    {
        #region Messages
        private const string k_Title = "~~~ Delegates Main Menu ~~~";
        private const string k_Back = "Back";
        private const string k_Quit = "Quit";
        private const string k_ShowWelcomeMsg = "Show Welcome";
        private const string k_ShowDateTimeMsg = "Show Date/Time";
        private const string k_ShowVersionMsg = "Show Version";
        private const string k_ShowDateMsg = "Show Date";
        private const string k_ShowTimeMsg = "Show Time";
        #endregion

        #region Data Members
        private readonly Menu r_MainMenu;
        #endregion

        #region Constructor
        public DelegateMenu()
        {
            r_MainMenu = new Menu(k_Title, k_Quit);

            r_MainMenu.AddMenu(CreateOption1());
            r_MainMenu.AddMenu(CreateOption2());
            r_MainMenu.AddMenu(CreateOption3());
        }
        #endregion

        #region Public Methods
        public void StartMenu()
        {
            r_MainMenu.onSelect();
        }
        #endregion

        #region Private Methods
        private ISelector CreateOption1()
        {
            MenuItem newMenuItem;

            newMenuItem = new MenuItem(k_ShowWelcomeMsg);
            newMenuItem.AttachActionToExecute(ExtentionFunctions.ShowWelcome);

            return newMenuItem;
        }

        private ISelector CreateOption2()
        {
            Menu newMenu;
            MenuItem newMenuItem;

            newMenu = new Menu(k_ShowDateTimeMsg, k_Back);
            newMenuItem = new MenuItem(k_ShowDateMsg);
            newMenuItem.AttachActionToExecute(ExtentionFunctions.ShowDate);
            newMenu.AddMenu(newMenuItem);
            newMenuItem = new MenuItem(k_ShowTimeMsg);
            newMenuItem.AttachActionToExecute(ExtentionFunctions.ShowTime);
            newMenu.AddMenu(newMenuItem);

            return newMenu;
        }

        private ISelector CreateOption3()
        {
            MenuItem newMenuItem;

            newMenuItem = new MenuItem(k_ShowVersionMsg);
            newMenuItem.AttachActionToExecute(ExtentionFunctions.ShowVersion);

            return newMenuItem;
        }
        #endregion
    }
}
